#include<bits/stdc++.h>
using namespace std;

int T,n,ans,red,blu,sum;
int t[200010],q[200010];

int main(){
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	scanf("%d",&T);
	while(T){
		T--;ans=0;red=0;blu=0;
		scanf("%d",&n);
		for(int i=1;i<=n;i++) scanf("%d",&t[i]);
		for(int i=0;i<(1<<n);i++){
			int zhi=i;sum=0;red=0;blu=0;
			for(int j=1;j<=n;j++){
				q[j]=zhi%2;
				zhi/=2;
			}
			for(int j=1;j<=n;j++){
				if(q[j]==0){
					if(red!=0){
						if(t[j]==t[red]) sum+=t[red];
						red=j;
					}
					else red=j;
				}else{
					if(blu!=0){
						if(t[j]==t[blu]) sum+=t[blu];
						blu=j;
					}
					else blu=j;
 				}
			}
			ans=max(ans,sum);
		}
		printf("%d\n",ans);
	}
	return 0;
} 
